package com.bdxk.android.imdemo.message;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bdxk.android.imdemo.R;

import io.rong.imkit.emoticon.AndroidEmoji;
import io.rong.imkit.model.ProviderTag;
import io.rong.imkit.model.UIMessage;
import io.rong.imkit.widget.provider.IContainerItemProvider;

@ProviderTag(messageContent = MyMessage.class,showPortrait = false,centerInHorizontal = true,showSummaryWithName = false)
public class CustomizeMessageItemProvider extends IContainerItemProvider.MessageProvider<MyMessage> {

    class ViewHolder {
        TextView message;
    }

    @Override
    public View newView(Context context, ViewGroup group) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_customize_message, null);
        ViewHolder holder = new ViewHolder();
        holder.message = (TextView) view.findViewById(R.id.tvContent);
        view.setTag(holder);
        return view;
    }


    @Override
    public void bindView(View view, int i, MyMessage myMessage, UIMessage uiMessage) {
        ViewHolder holder = (ViewHolder) view.getTag();

//        if (uiMessage.getMessageDirection() == Message.MessageDirection.SEND) {//消息方向，自己发送的
//            holder.message.setBackgroundResource(io.rong.imkit.R.drawable.rc_ic_bubble_right);
//        } else {
//            holder.message.setBackgroundResource(io.rong.imkit.R.drawable.rc_ic_bubble_left);
//        }
        holder.message.setText(myMessage.getContent());
        AndroidEmoji.ensure(new SpannableString(holder.message.getText()));//显示消息中的 Emoji 表情。
    }

    @Override
    public Spannable getContentSummary(MyMessage data) {
        return new SpannableString(data.getContent());
    }

    @Override
    public void onItemClick(View view, int i, MyMessage myMessage, UIMessage uiMessage) {

    }

    @Override
    public void onItemLongClickAction(View view, int position, UIMessage message) {
        super.onItemLongClickAction(view, position, message);
    }
}